package com.Dorso;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;


public class Main
{

    public static void main(String[] args)
    {
        //读取myapp.properties文件
        Properties props = new Properties();
        try (InputStream input =
                     Main.class.getResourceAsStream("/myapp.properties"))
        {
            if (input == null) {return;}
            props.load(input);
//            获取该类的Class Type
            Class<?> cls = Class.forName(props.getProperty("bootstrapClass"));
//            创建com.Dorso.MyClass类型的实例对象
            Object obj=cls.newInstance();
//            通过getMethod方法获取Method对象
            for (Method method : cls.getMethods())
            {
//            isAnnotationPresent若方法应用此注解则返回true，否则返回false
                if (method.isAnnotationPresent(InitMethod.class))
                {
//            调用invoke方法来执行obj的方法
                    method.invoke(obj);
                }
            }
        }

        catch (IOException | ClassNotFoundException | InstantiationException |
                 IllegalAccessException |
                 InvocationTargetException e)
        {
            System.out.println("Load properties error!");
        }

    }
}
